---
category: String
created: '2021-05-27'
title: Replace all tab characters with spaces
updated: '2021-10-13'
---

**JavaScript version**

```js replace.js
const replace = (str, numSpaces = 4) => str.replaceAll('\t', ' '.repeat(numSpaces));
```

**TypeScript version**

```ts replace.ts
const replace = (str: string, numSpaces = 4): string => str.replaceAll('\t', ' '.repeat(numSpaces));
```
